import { defineStore } from 'pinia';
import { ref } from 'vue';
import type { CartItem } from './cart';

/**
 * 订单状态管理
 */

export interface OrderAddress {
  addressId: string;
  contactName: string;
  contactPhone: string;
  fullAddress: string;
}

export interface OrderInfo {
  merchantId: number;
  merchantName: string;
  items: CartItem[];
  totalPrice: number;
  deliveryFee: number;
  address: OrderAddress | null;
  remark: string;
}

export const useOrderStore = defineStore('order', () => {
  // 当前待结算订单
  const currentOrder = ref<OrderInfo | null>(null);

  // 设置订单信息
  const setOrderInfo = (order: OrderInfo) => {
    currentOrder.value = order;
  };

  // 清空订单信息
  const clearOrderInfo = () => {
    currentOrder.value = null;
  };

  return {
    currentOrder,
    setOrderInfo,
    clearOrderInfo
  };
});